package com.lemon.smartsafetynew.ui.adapter.common;

import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.lemon.smartsafety.R;
import com.lemon.smartsafety.listener.RecyclerTClickListener;
import com.lemon.smartsafetynew.util.common.CommonUtil;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import kale.adapter.LemonRcvAdapter;
import kale.adapter.item.AdapterItem;

/**
 * Created by Andrew on 2017/9/14.
 */

public class StringAdapter extends LemonRcvAdapter<String> {

    private RecyclerTClickListener<String> mListener;

    public StringAdapter(@Nullable List<String> data,
                         RecyclerTClickListener<String> mListener) {
        super(data);
        this.mListener = mListener;
    }

    @NonNull
    @Override
    public AdapterItem createItem(Object type) {
        return new ItemAdapter();
    }

    public class ItemAdapter implements AdapterItem<String> {

        private String mData;
        private int mPosition;

        @Bind(R.id.content_tv)
        TextView contentTv;
        @Bind(R.id.layout)
        LinearLayout layout;

        @Override
        public int getLayoutResId() {
            return R.layout.item_string;
        }

        @Override
        public void bindViews(View root) {
            ButterKnife.bind(this, root);
        }

        @Override
        public void setViews() {
            layout.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    mListener.onItemClick(mData, mPosition);
                }
            });
        }

        @Override
        public void handleData(String s, int position) {

            mData = s;
            mPosition = position;

            contentTv.setText(CommonUtil.avoidNullString(s));
        }
    }
}
